package fictional.GUI;

import java.io.IOException;

import fictional.Common.CharacterItem;
import fictional.Common.GenderItem;
import fictional.Common.IBL;
import fictional.Common.PlaceItem;
import fictional.Common.Response;
import fictional.Common.SpeciesItem;

/**
 * This task edits the logged in user's information after he
 * has clicked the 'edit information' button.
 */
public class AddEditUserTask extends DefaultTask{
	
    GenderItem gender;
    SpeciesItem species;
    String organization = "";
    String birthDate = "";
    PlaceItem birthPlace;
    String occupations = "";
    String superPowers = "";
    CharacterItem character;
    
    public AddEditUserTask(org.jdesktop.application.Application app)
    {
        super(app);
    }
    
    public void setTask(IBL BL, GUI gui, CharacterItem character, GenderItem gender, SpeciesItem species, String organization, PlaceItem birthPlace, String occupations, String superPowers)
    {
        this.BL = BL;
        this.gui = gui;
        this.gender = gender;
        this.species = species;
        this.organization = organization;
        this.birthPlace = birthPlace;
        this.occupations = occupations;
        this.superPowers = superPowers;
        this.character = character;
    }

    @Override
    protected Object doInBackground() throws IOException, InterruptedException
    {
        response = new Response();
        BL.editCharacterInformation(character, character.getName(), gender, species, organization, birthPlace, occupations, superPowers, response);

        if (response.isIs_Success())
        {
        	gui.initInfoDisplay();
        	isSuccessMessageNeeded = true;
        	successMessage = "Information updated successfully.";
        }
        else
        {
        	errorTitle = "Error Updating Information";
        }
        
        return null;
    }

}
